package info.xiao.dataStructrue.array;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname BinomialArray
 * @Description 杨辉三角形2
 * @Url https://leetcode.cn/problems/pascals-triangle-ii/
 * @Date 2023/4/14 10:33
 * @Created by 晓龙Oba
 */
public class BinomialArray {

    public static void main(String[] args) {
        int rowIndex = 3;
        List<Integer> result = getRow(rowIndex);
        System.out.println(result);
    }

    private static List<Integer> getRow(int rowIndex) {
        List<List<Integer>> lists = new ArrayList<>();
        // 生成一个杨辉三角形 然后取对应行数
        for (int i = 0; i <= rowIndex; i++) {
            ArrayList<Integer> result = new ArrayList<>();
            for (int j = 0; j < i + 1; j++) {
                if (j == 0 || j == i) {
                    result.add(1);
                    continue;
                }
                List<Integer> front = lists.get(i - 1);
                result.add(front.get(j - 1) + front.get(j));
            }
            lists.add(result);
        }


        return lists.get(rowIndex);
    }

}
